<style lang="less">
</style>

<template>
    <div>
        <Card shadow>
            <iview-table
                ref="table"
                :status="status"
                :baseURL="queryModel.baseURL"
                :menuId="dataModel.menuId"
                :columns="dataModel.columns"
                :order="dataModel.order"
                :pageNumber="pageModel.pageNumber"
                :pageSize="pageModel.pageSize"
                v-on="{changeTotalSize:changeTotalSize,events:events,changeSelect:changeSelect}">
            </iview-table>
            <br>
            <iview-page 
                :totalSize="pageModel.totalSize"
                :pageNumber="pageModel.pageNumber" 
                :pageSize="pageModel.pageSize"
                :pageSizeOpts="pageModel.pageSizeOpts"
                v-on="{changePageNumber:changePageNumber,changePageSize:changePageSize}">
            </iview-page>
        </Card>
    </div>
</template>

<script>
import iviewTable from '@/view/common/table/Table.vue';
import iviewPage from '@/view/common/page/Page.vue';
export default {
    name: 'text-editor',
    components: {
        iviewTable,
        iviewPage
    },
    data () {
        return {
            status: false,
            selectRows: [],
            queryModel: {
                // 网关代理路径+资源路径
                baseURL: '/user/role'
            },
            dataModel: {
                menuId: 120,
                columns: [
                    {
                        type: 'selection',
                        width: 60,
                        align: 'center'
                    },{
                        title: '角色代码',
                        key: 'roleCode'
                    },{
                        title: '角色名称',
                        key: 'roleName'
                    },{
                        title: '角色描述',
                        key: 'roleDesc'
                    }
                ],
                order: 'id desc'
            },
            pageModel: {
                totalSize: 0,
                pageNumber: 1,
                pageSize: 10,
                pageSizeOpts: [10, 50, 100, 500]
            }
        };
    },
    methods: {
        events (item) {
            if (item.path === 'add') {
                this.add()
            } else if (item.path === 'addAuth') {
                this.addAuth()
            }
        },
        add () {

        },
        addAuth () {
            if (this.selectRows.length !== 1) {
                this.$bus.alert('warning', '请选择一条记录', 3)
                this.status = !this.status
                return
            }
            let row = this.selectRows[0]
            let query = {
                id: row.id
            }
            this.$bus.toPath('/role/roleMenus', query)
        },
        changeSelect (rows) {
            this.selectRows = rows
        },
        changeTotalSize (totalSize) {
            this.pageModel.totalSize = totalSize
        },
        changePageNumber (pageNumber) {
            this.pageModel.pageNumber = pageNumber
        },
        changePageSize (pageSize) {
            this.pageModel.pageSize = pageSize
        },
        refresh () {
            this.$refs.table.refresh()
        },
        init () {
            this.refresh()
        }
    },
    watch: {
        '$route' (to) {
            if (to.path === '/role') {
                this.init()
            }
        }
    },
    mounted () {
        this.init()
    }
};
</script>

<style>

</style>
